﻿using System;
using System.Windows.Ria.ApplicationServices;

namespace SoftSource.Ria
{
    public static class AuthenticationServiceExtensions
    {
        public static IObservable<LoginOperation> WhenLogin(this AuthenticationService authenticationService, LoginParameters parameters)
        {
            return OperationBaseEx.ToObservable<LoginOperation>(handler => authenticationService.Login(parameters, handler, null));
        }

        public static IObservable<LogoutOperation> WhenLogout(this AuthenticationService authenticationService)
        {
            return OperationBaseEx.ToObservable<LogoutOperation>(handler => authenticationService.Logout(handler, null));
        }

        public static IObservable<SaveUserOperation> WhenSaveUser(this AuthenticationService authenticationService)
        {
            return OperationBaseEx.ToObservable<SaveUserOperation>(handler => authenticationService.SaveUser(handler, null));
        }

        public static IObservable<LoadUserOperation> WhenLoadUser(this AuthenticationService authenticationService)
        {
            return OperationBaseEx.ToObservable<LoadUserOperation>(handler => authenticationService.LoadUser(handler, null));
        }
    }
}
